package com.online.college.rest.business;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.online.college.core.consts.domain.ConstsClassify;
import com.online.college.core.consts.service.IConstsClassifyService;
import com.online.college.rest.dto.ClassifyDto;

@Service
public class ClassifyServiceImpl implements IClassifyService {

	@Autowired
	private IConstsClassifyService classifyService;

	@Override
	public Map<String, ClassifyDto> getClassifyList() {
		List<ConstsClassify> allClassify = classifyService.queryAll();
		Map<String, ClassifyDto> returnMap = new HashMap<String, ClassifyDto>();
		ClassifyDto temp = new ClassifyDto();
		for (ConstsClassify classify : allClassify) {
			if ("0".equals(classify.getParentCode())) {
				ClassifyDto classifyDto = new ClassifyDto();
				BeanUtils.copyProperties(classify, classifyDto);
				returnMap.put(classify.getCode(), classifyDto);
			} else if (null != returnMap.get(classify.getParentCode())) {
				temp = returnMap.get(classify.getParentCode());
				temp.getSubClassify().add(classify);
			}
		}
		return returnMap;
	}

}
